package com.hemerasolutions.v2trainer.model.users;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import com.hemerasolutions.v2trainer.model.base.BaseModel;
import com.hemerasolutions.v2trainer.model.exercise.Equipment;
import com.hemerasolutions.v2trainer.model.interfaces.AgreementHolderInterface;
import com.hemerasolutions.v2trainer.model.multimedia.Photo;
import com.hemerasolutions.v2trainer.model.others.Theme;

@Entity
public class PersonalTrainer extends BaseModel  implements AgreementHolderInterface {
 
	private static final long serialVersionUID = 1L;

    @Column(length = 20)
	private String firstName;

    @Column(length = 50)
	private String lastName;
	 
    @Column(length = 18)
	private String cnpj;
	 
    @Column(length = 14)
    private String cpf;
	
    @Column(length = 50)
    private String address;

    @Column(length = 30)
	private String state;

    @Column(length = 30)
	private String city;

    @Column(length = 9)
	private String postalCode;	

    @Column
	private boolean male;
    
    @OneToOne(cascade=CascadeType.ALL)
    private User user;

    @OneToOne(cascade=CascadeType.ALL,orphanRemoval=true)  
    private Photo photo;    
    
    @OneToOne(cascade=CascadeType.ALL,orphanRemoval=true) 
    private Photo logo;

    @OneToOne(cascade=CascadeType.ALL,orphanRemoval=true)
    private Photo wideLogo;    

    @OneToOne
    private Theme theme;

    @OneToMany
 	private List<Equipment> equipments;

    @ManyToMany(mappedBy = "personalTrainers", fetch = FetchType.LAZY)
    private List<Athlete> athletes;

    
	public PersonalTrainer() {
		super();

		this.user 		= new User();
		this.theme	 	= new Theme();
		this.equipments = new ArrayList<Equipment>();
		this.athletes 	= new ArrayList<Athlete>();		
		
	}

	public User getUser() {
		return user;
	}
	
	public String getName(){
		return this.firstName + " " + this.lastName;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public Photo getPhoto() {
		return photo;
	}

	public String getFirstName() {
		return firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public String getCnpj() {
		return cnpj;
	}

	public String getCpf() {
		return cpf;
	}

	public String getAddress() {
		return address;
	}

	public String getState() {
		return state;
	}

	public String getCity() {
		return city;
	}

	public String getPostalCode() {
		return postalCode;
	}

	public Photo getLogo() {
		return logo;
	}

	public Photo getWideLogo() {
		return wideLogo;
	}

	public Theme getTheme() {
		return theme;
	}


	public List<Equipment> getEquipments() {
		return equipments;
	}

	public List<Athlete> getAthletes() {
		return athletes;
	}

	public void setPhoto(Photo photo) {
		this.photo = photo;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public void setCnpj(String cnpj) {
		this.cnpj = cnpj;
	}

	public void setCpf(String cpf) {
		this.cpf = cpf;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public void setState(String state) {
		this.state = state;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}

	public void setLogo(Photo logo) {
		this.logo = logo;
	}

	public void setWideLogo(Photo wideLogo) {
		this.wideLogo = wideLogo;
	}

	public void setTheme(Theme theme) {
		this.theme = theme;
	}

	public void setEquipments(List<Equipment> equipments) {
		this.equipments = equipments;
	}

	public void setAthletes(List<Athlete> athletes) {
		this.athletes = athletes;
	}
	
	public boolean isMale() {
		return male;
	}

	public void setMale(boolean male) {
		this.male = male;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((address == null) ? 0 : address.hashCode());
		result = prime * result + ((city == null) ? 0 : city.hashCode());
		result = prime * result + ((cnpj == null) ? 0 : cnpj.hashCode());
		result = prime * result + ((cpf == null) ? 0 : cpf.hashCode());
		result = prime * result
				+ ((equipments == null) ? 0 : equipments.hashCode());
		result = prime * result
				+ ((firstName == null) ? 0 : firstName.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((lastName == null) ? 0 : lastName.hashCode());
		result = prime * result + ((logo == null) ? 0 : logo.hashCode());
		result = prime * result + (male ? 1231 : 1237);
		result = prime * result + ((photo == null) ? 0 : photo.hashCode());
		result = prime * result
				+ ((postalCode == null) ? 0 : postalCode.hashCode());
		result = prime * result + ((state == null) ? 0 : state.hashCode());
		result = prime * result + ((theme == null) ? 0 : theme.hashCode());
		result = prime * result + ((user == null) ? 0 : user.hashCode());
		result = prime * result
				+ ((wideLogo == null) ? 0 : wideLogo.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PersonalTrainer other = (PersonalTrainer) obj;
		if (address == null) {
			if (other.address != null)
				return false;
		} else if (!address.equals(other.address))
			return false;
		if (city == null) {
			if (other.city != null)
				return false;
		} else if (!city.equals(other.city))
			return false;
		if (cnpj == null) {
			if (other.cnpj != null)
				return false;
		} else if (!cnpj.equals(other.cnpj))
			return false;
		if (cpf == null) {
			if (other.cpf != null)
				return false;
		} else if (!cpf.equals(other.cpf))
			return false;
		if (equipments == null) {
			if (other.equipments != null)
				return false;
		} else if (!equipments.equals(other.equipments))
			return false;
		if (firstName == null) {
			if (other.firstName != null)
				return false;
		} else if (!firstName.equals(other.firstName))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (lastName == null) {
			if (other.lastName != null)
				return false;
		} else if (!lastName.equals(other.lastName))
			return false;
		if (logo == null) {
			if (other.logo != null)
				return false;
		} else if (!logo.equals(other.logo))
			return false;
		if (male != other.male)
			return false;
		if (photo == null) {
			if (other.photo != null)
				return false;
		} else if (!photo.equals(other.photo))
			return false;
		if (postalCode == null) {
			if (other.postalCode != null)
				return false;
		} else if (!postalCode.equals(other.postalCode))
			return false;
		if (state == null) {
			if (other.state != null)
				return false;
		} else if (!state.equals(other.state))
			return false;
		if (theme == null) {
			if (other.theme != null)
				return false;
		} else if (!theme.equals(other.theme))
			return false;
		if (user == null) {
			if (other.user != null)
				return false;
		} else if (!user.equals(other.user))
			return false;
		if (wideLogo == null) {
			if (other.wideLogo != null)
				return false;
		} else if (!wideLogo.equals(other.wideLogo))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "PersonalTrainer [id=" + id + ", firstName=" + firstName
				+ ", lastName=" + lastName + ", cnpj=" + cnpj + ", cpf=" + cpf
				+ ", address=" + address + ", state=" + state + ", city="
				+ city + ", postalCode=" + postalCode + ", male=" + male
				+ ", user=" + user + ", photo=" + photo + ", logo=" + logo
				+ ", wideLogo=" + wideLogo + ", theme=" + theme
				+ ", equipments=" + equipments + "]";
	}

}
 
